﻿Public Class LoadDetails

    Private Sub LoadDetails_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'CustomerDataSet.Customer' table. You can move, or remove it, as needed.
        Dim databaseProvider As DatabaseProvider = databaseProvider.Instance()
        LstDetails.DataSource = databaseProvider.GetAllCustomers()
        
    End Sub

    Private Sub BtnLoadDetails_Click(sender As System.Object, e As System.EventArgs) Handles BtnLoadDetails.Click
        Sales.TxtCustomerID.Text = LstDetails.SelectedItem.Row.ItemArray(0)
        Sales.TxtCustomerName.Text = LstDetails.SelectedItem.Row.ItemArray(1)
        Sales.TxtCustomerSurname.Text = LstDetails.SelectedItem.Row.ItemArray(2)
        Sales.TxtCustomerTown.Text = LstDetails.SelectedItem.Row.ItemArray(5)
        Sales.TxtCustomerPostcode.Text = LstDetails.SelectedItem.Row.ItemArray(6)
        Sales.TxtCustomerAddress1.Text = LstDetails.SelectedItem.Row.ItemArray(7)
        Sales.TxtCustomerAddress2.Text = LstDetails.SelectedItem.Row.ItemArray(8)
        Sales.TxtCustomerHome.Text = LstDetails.SelectedItem.Row.ItemArray(4)
        Sales.TxtCustomerMobile.Text = LstDetails.SelectedItem.Row.ItemArray(3)
        Me.Close()
    End Sub

    Private Sub TxtSearch_TextChanged(sender As System.Object, e As System.EventArgs) Handles TxtSearch.TextChanged
        Dim i As Integer = LstDetails.FindString(TxtSearch.Text)
        LstDetails.SelectedIndex = i
        If TxtSearch.Text = "" Then
            LstDetails.SelectedIndex = -1
        End If
    End Sub
End Class